﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DungeonGenerator;

namespace PitOfDespair.Controllers
{
	using System.Text;

	public partial class DungeonController : Controller
    {
        //
        // GET: /Dungeon/
        public virtual ActionResult Index()
        {
            if (TempData["Error"] != null)
                ViewBag.Error = TempData["Error"];
            return View();
        }
		public virtual ActionResult Details(int seed=0, int x=20, int y=20, int features=10)
        {
            var rnd = new TestRandomizer(seed);
					var generatorLog = new StringBuilder();
					var model = new DungeonGenerator.Java.Generator(rnd, s => generatorLog.Append(s), false);
		    try
		    {
                if (model.CreateDungeon(x, y, features)) return this.View(model);
		    }
		    catch (Exception ex)
		    {
		        TempData["Error"] ="Failed to generate dungeon, please try again with different parameters ("+ ex.Message+")";
		        Trace.WriteLine(ex.Message);
		    }

		    return RedirectToAction(MVC.Dungeon.Index());
            
				
        }

    }
}
